package com.atstudying.mallsearch.controller;

import com.atstudying.mallsearch.service.MallSearchService;
import com.atstudying.mallsearch.vo.SearchParam;
import com.atstudying.mallsearch.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.io.IOException;

/**
 * @author Mr.zhneg
 * @create 2020-11-04-22:08
 */

@Controller
public class SearchController {

    @Autowired
    MallSearchService mallService;

    /**
     * 自动将页面提交过来的所有请求查询参数封装成指定的对象
     *
     * @param searchParam
     * @return
     */
    @GetMapping("/list.html")
    public String listPage(SearchParam searchParam, Model model) throws IOException {

        //1：根据传递来的页面的查询参数，去es中检索商品，并且返回SearchResult
        SearchResult result = mallService.search(searchParam);
        model.addAttribute("result", result);
        System.out.println("receive request .....");

        return "list";
    }


}